package com.aruba.gifapplication;

import android.graphics.Bitmap;

import java.io.FileDescriptor;

public class GifHandler {
    private long gifAddr;

    static {
        System.loadLibrary("native-lib");
    }

    public GifHandler(FileDescriptor fileDescriptor, long offset) {
        this.gifAddr = loadFd(fileDescriptor, offset);
    }

    /**
     * 加载gif资源文件
     *
     * @param fileDescriptor
     * @param offset
     * @return
     */
    private native long loadFd(FileDescriptor fileDescriptor, long offset);

    /**
     * 获取图片的宽
     *
     * @param ndkGif
     * @return
     */
    public native int getWidth(long ndkGif);

    /**
     * 获取图片的高
     *
     * @param ndkGif
     * @return
     */
    public native int getHeight(long ndkGif);

    public native int updateFrame(long ndkGif, Bitmap bitmap);

    public int getWidth() {
        return getWidth(gifAddr);
    }

    public int getHeight() {
        return getHeight(gifAddr);
    }

    /**
     * 更新bitmap到下一帧
     *
     * @param bitmap
     * @return
     */
    public int updateFrame(Bitmap bitmap) {
        return updateFrame(gifAddr, bitmap);
    }
}
